package com.larry.mr.writablecomparable;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @ProjectName hadoop
 * @Author larry
 * @Date 17:47 2021/11/15
 * @Description TODO
 **/
public class FlowMapper extends Mapper<LongWritable, Text,FlowBean,Text> {

    private Text outV = new Text();

    private FlowBean outK = new FlowBean();

    /**
     *      1	13736230513	192.196.100.1	www.atguigu.com	2481	24681	200
     * @param key
     * @param value
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] split = line.split("\t");

        outV.set(split[1]);
        outK.setUpFlow(Integer.valueOf(split[split.length - 3]));
        outK.setDownFlow(Integer.valueOf(split[split.length - 2]));
        outK.setSumFlow();

        context.write(outK,outV);
    }
}
